package com.cd.cms.common.utils;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * MultipartFile转换为File
 *
 * @author ozy
 */
public class MultipartFileToFileUtils {

    public static String multipartFileToFile(MultipartFile multipartFile, HttpServletRequest request) throws IOException {
        String realPath = request.getSession().getServletContext().getRealPath("/WEB-INF/upload");
        String filename = multipartFile.getOriginalFilename();
        try {
            FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), new File(realPath, filename));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return realPath + "\\" + filename;
    }

}
